<template>
	<div class="h-full flex flex-col">
		<a-card>
			<div slot="title">
				<a-space>
					<div class="ty"></div>
					{{ $t('user.password.strength.short') }}
				</a-space>
			</div>
			<!-- 头部数据统计 -->
			<headerBands ref="headerBands" />
		</a-card>
		<a-card class="mt-[10px]">
			<div style="display: flex;margin-bottom: 20px;">
        <a-button type="link" :class="isLable === 0 ? 'active' : ''" class="button-text" @click="clickButton(0)">{{
          $t('user.verification-code.myRpa') }}</a-button>
        <a-button type="link" :class="isLable === 1 ? 'active' : ''" class="button-text" @click="clickButton(1)">{{
          $t('user.verification-code.allRpa') }}</a-button>
				<div style="position: absolute; right: 32px;">
					<!-- 操作按钮 -->
					<a-dropdown style="position: relative;">
						<a-menu slot="overlay">
							<a-menu-item key="1" @click="showModal('add')">
								{{ $t('user.email.wrong-format') }}
							</a-menu-item>
							<a-menu-item
								key="2"
								@click="start"
								v-if="userroleid.indexOf('35') != -1"
								:disabled="!hasSelected"
							>
								{{ $t('user.password.strength.low222333') }}
							</a-menu-item>
						</a-menu>
						<a-button type="primary">
							<a-icon type="bars" />
							{{ $t('di.menus') }}
							<a-icon type="down" />
						</a-button>
					</a-dropdown>
				</div>
      </div>
			<!-- 主列表 -->
			<a-table
				ref="table"
				:dataSource="listData"
				:loading="listLoading"
				:pagination="false"
				:rowKey="(record) => record.Id"
				:scroll="{ x: 2000, y: 2000 }"
				class="h-full overflow-x-auto"
				size="middle"
				@change="tableChange"
				:locale="customLocale"
			>
				<!-- RPA ID  -->
				<a-table-column
					key="RpaId"
					data-index="RpaId"
					width="60px"
					@filterDropdownVisibleChange="
						(e) => {
							if (e) this.setValus(1)
						}
					"
				>
					<span slot="title">RPA ID</span>
					<span
						slot="filterDropdown"
						slot-scope="{
							setSelectedKeys,
							selectedKeys,
							confirm,
							clearFilters,
							column,
						}"
					>
						<table-select
							ref="tableselect1"
							:filter-data="filterData"
							@searchCommit="searchQuery"
							@searchFilter="searchQueryFilter"
							@searchClose="confirm"
							@searchClean="tableCleanJobs"
						/>
					</span>
				</a-table-column>
				<!-- 业务名称 -->
				<a-table-column
					key="RpaName"
					data-index="RpaName"
					width="120px"
					@filterDropdownVisibleChange="
						(e) => {
							if (e) this.setValus(2)
						}
					"
				>
					<span slot="title">{{
						$t('user.password.strength.medium')
					}}</span>
					<span
						slot="filterDropdown"
						slot-scope="{
							setSelectedKeys,
							selectedKeys,
							confirm,
							clearFilters,
							column,
						}"
					>
						<table-select
							ref="tableselect2"
							:filter-data="filterData"
							@searchCommit="searchQuery"
							@searchClose="confirm"
							@searchClean="tableCleanJobs"
							@searchFilter="searchQueryFilter"
						/>
					</span>
				</a-table-column>
				<!-- 数据控制者 -->
				<a-table-column
					key="RpaDataController"
					data-index="RpaDataController"
					width="80px"
					@filterDropdownVisibleChange="(e) => (this.setValusKey = 3)"
				>
					<span slot="title">{{ $t('user.login.remember-me') }}</span>
					<span
						slot="filterDropdown"
						slot-scope="{
							setSelectedKeys,
							selectedKeys,
							confirm,
							clearFilters,
							column,
						}"
					>
						<table-select
							ref="tableselect3"
							:filter-data="[]"
							@searchCommit="searchQuery"
							@searchClose="confirm"
							@searchClean="tableCleanJobs"
						/>
					</span>
				</a-table-column>
				<!-- 业务负责人 -->
				<a-table-column
					key="RpaLeaderMaster"
					data-index="RpaLeaderMaster"
					width="80px"
					@filterDropdownVisibleChange="
						(e) => {
							if (e) this.setValus(4)
						}
					"
				>
					<span slot="title">{{
						$t('user.password.strength.low')
					}}</span>
					<span
						slot="filterDropdown"
						slot-scope="{
							setSelectedKeys,
							selectedKeys,
							confirm,
							clearFilters,
							column,
						}"
					>
						<table-select
							ref="tableselect4"
							:single-search="false"
							:filter-data="filterData"
							@searchFilter="searchQueryFilter"
							@searchClose="confirm"
							@searchClean="tableCleanJobs"
						/>
					</span>
				</a-table-column>
				<!-- 本业务涉及的数据处理阶段有哪些 -->
				<a-table-column
					key="RpaProcessingActivityCycle"
					:data-index="
						itLang
							? 'RpaProcessingActivityCycle'
							: 'RpaProcessingActivityCycleEn'
					"
					width="80px"
					@filterDropdownVisibleChange="
						(e) => {
							if (e) this.setValus(5)
						}
					"
				>
					<span slot="title">{{
						$t('user.verification-code.required1133')
					}}</span>
					<span
						slot="filterDropdown"
						slot-scope="{
							setSelectedKeys,
							selectedKeys,
							confirm,
							clearFilters,
							column,
						}"
					>
						<table-select
							ref="tableselect5"
							:single-search="false"
							:filter-data="filterData"
							@searchFilter="searchQueryFilter"
							@searchClose="confirm"
							@searchClean="tableCleanJobs"
						/>
					</span>
				</a-table-column>
				<!-- 是否涉及线上处理活动 -->
				<a-table-column
					key="RpaCollectionChannels"
					:data-index="
						itLang
							? 'RpaCollectionChannels'
							: 'RpaCollectionChannelsEn'
					"
					width="80px"
					@filterDropdownVisibleChange="
						(e) => {
							if (e) this.setValus(6)
						}
					"
				>
					<span slot="title">{{
						$t(
							'user.verification-code.required1115661105773714422813'
						)
					}}</span>
					<span
						slot="filterDropdown"
						slot-scope="{
							setSelectedKeys,
							selectedKeys,
							confirm,
							clearFilters,
							column,
						}"
					>
						<table-select
							ref="tableselect6"
							:single-search="false"
							:filter-data="filterData"
							@searchFilter="searchQueryFilter"
							@searchClose="confirm"
							@searchClean="tableCleanJobs"
						/>
					</span>
				</a-table-column>
				<!-- 创建人 -->
				<a-table-column
					key="CreatePeople"
					data-index="CreatePeople"
					width="60px"
					@filterDropdownVisibleChange="
						(e) => {
							if (e) this.setValus(10)
						}
					"
				>
					<span slot="title"
						>{{
							$t('user.verification-code.required1115661105793')
						}}
					</span>
					<span
						slot="filterDropdown"
						slot-scope="{
							setSelectedKeys,
							selectedKeys,
							confirm,
							clearFilters,
							column,
						}"
					>
						<table-select
							ref="tableselect10"
							:filter-data="filterData"
							@searchCommit="searchQuery"
							@searchClose="confirm"
							@searchClean="tableCleanJobs"
							@searchFilter="searchQueryFilter"
						/>
					</span>
				</a-table-column>
				<!-- 创建时间 -->
				<a-table-column
					key="RpaCreatetime"
					data-index="RpaCreatetime"
					width="90px"
					@filterDropdownVisibleChange="
						(e) => {
							if (e) this.setValus(11)
						}
					"
				>
					<span slot="title">{{
						$t('user.verification-code.required111566131')
					}}</span>
					<span
						slot="filterDropdown"
						slot-scope="{
							setSelectedKeys,
							selectedKeys,
							confirm,
							clearFilters,
							column,
						}"
					>
						<table-select
							ref="tableselect11"
							:single-search="false"
							:filter-data="filterData"
							@searchFilter="searchQueryFilter"
							@searchClose="confirm"
							@searchClean="tableCleanJobs"
						/>
					</span>
				</a-table-column>
				<!-- 最后更新时间 -->
				<a-table-column
					key="RpaUpdatetime"
					data-index="RpaUpdatetime"
					width="90px"
					@filterDropdownVisibleChange="
						(e) => {
							if (e) this.setValus(12)
						}
					"
				>
					<span slot="title"
						>{{
							$t('user.verification-code.required1115661105752')
						}}
					</span>
					<span
						slot="filterDropdown"
						slot-scope="{
							setSelectedKeys,
							selectedKeys,
							confirm,
							clearFilters,
							column,
						}"
					>
						<table-select
							ref="tableselect12"
							:single-search="false"
							:filter-data="filterData"
							@searchFilter="searchQueryFilter"
							@searchClose="confirm"
							@searchClean="tableCleanJobs"
						/>
					</span>
				</a-table-column>
				<!-- 关联的数据资产ID -->
				<a-table-column
					key="DataAssetsId"
					data-index="DataAssetsId"
					width="70px"
					@filterDropdownVisibleChange="
						(e) => {
							if (e) this.setValus(13)
						}
					"
				>
					<span slot="title">{{
						$t('user.verification-code.related')
					}}</span>
					<span
						slot="filterDropdown"
						slot-scope="{
							setSelectedKeys,
							selectedKeys,
							confirm,
							clearFilters,
							column,
						}"
					>
						<table-select
							ref="tableselect13"
							:filter-data="filterData"
							@searchCommit="searchQuery"
							@searchClose="confirm"
							@searchClean="tableCleanJobs"
							@searchFilter="searchQueryFilter"
						/>
					</span>
					<template slot-scope="text">
						<DIdetail :DIdetailId = "text" :initData="initData" :fetchData = "fetchData"/>
					</template>
				</a-table-column>
				<!-- 关联的DPIA ID -->
				<a-table-column
					key="DPIAId"
					data-index="DPIAId"
					width="90px"
					@filterDropdownVisibleChange="
						(e) => {
							if (e) this.setValus(14)
						}
					"
				>
					<span slot="title"
						>{{ $t('user.verification-code.relatedDPIA') }}
					</span>
					<span
						slot="filterDropdown"
						slot-scope="{
							setSelectedKeys,
							selectedKeys,
							confirm,
							clearFilters,
							column,
						}"
					>
						<table-select
							ref="tableselect14"
							:filter-data="filterData"
							@searchCommit="searchQuery"
							@searchClose="confirm"
							@searchClean="tableCleanJobs"
							@searchFilter="searchQueryFilter"
						/>
					</span>
					<template slot-scope="text">
						<Dpiadetail :DpiadetailId = "text"/>
					</template>
				</a-table-column>
				<!-- 状态 -->
				<a-table-column
					key="RpaState"
					:title="$t('user.verification-code.required1115661101')"
					width="50px"
					@filterDropdownVisibleChange="
						(e) => {
							if (e) this.setValus(7)
						}
					"
				>
					<span
						slot="filterDropdown"
						slot-scope="{
							setSelectedKeys,
							selectedKeys,
							confirm,
							clearFilters,
							column,
						}"
					>
						<table-select
							ref="tableselect7"
							:single-search="false"
							:filter-data="filterData"
							@searchFilter="searchQueryFilter"
							@searchClose="confirm"
							@searchClean="tableCleanJobs"
						/>
					</span>
					<template slot-scope="text, record">
						<span>
							<div v-if="record.RpaState == 'Draft'">
								<a-badge color="blue" />
								{{
									$t(
										'user.verification-code.required111566133'
									)
								}}
							</div>
							<div v-else-if="record.RpaState == 'Active'">
								<a-badge status="success" />
								{{ $t('user.v156') }}
							</div>
							<div v-else>
								<a-badge color="red" /> {{ record.RpaState }}
							</div>
						</span>
					</template>
				</a-table-column>
				<!-- 操作 -->
				<a-table-column
					key="action"
					:title="$t('menu.exception.not-find')"
					width="80px"
					fixed="right"
				>
					<template slot-scope="record">
						<span>
							<a-dropdown>
								<a-button type="link">
									<a-icon type="more" />
								</a-button>
								<template #overlay>
									<a-menu>
										<a-menu-item
											v-if="
												record.DPIAId == '' &&
												userdata.YtId ===
													record.RpaCreatePeople
											"
											@click="edit(record.Id)"
										>
											<!-- 修改按钮 -->
											<a-button type="link">{{
												$t(
													'user.verification-code.required111566147'
												)
											}}</a-button>
										</a-menu-item>
										<a-menu-item
											v-if="record.RpaState === 'Active'"
										>
											<!-- 复制 -->
											<a-popconfirm
												:cancel-text="
													$t('user.email.required11')
												"
												:ok-text="
													$t(
														'user.verification-code.required1166'
													)
												"
												:title="
													$t(
														'menu.account.logout11229922779945445'
													)
												"
												@confirm="() => Copy(record.Id)"
											>
												<a-button
													type="link"
													style="
														width: 100%;
														text-align: left;
													"
													>{{
														$t(
															'user.confirm-password.required'
														)
													}}</a-button
												>
											</a-popconfirm>
										</a-menu-item>
										<a-menu-item @click="see(record.Id)">
											<!-- 查看 -->
											<a-button type="link">{{
												$t(
													'user.verification-code.required1115661105718'
												)
											}}</a-button>
										</a-menu-item>
										<a-menu-item
											v-if="
												(record.DpiaState === 0 &&
													userdata.YtId ===
														record.RpaCreatePeople) ||
												record.DPIAId === ''
											"
										>
											<!-- 删除 -->
											<a-popconfirm
												:cancel-text="
													$t('user.email.required11')
												"
												:ok-text="
													$t(
														'user.verification-code.required1166'
													)
												"
												:title="
													$t(
														'user.verification-code.required111566110577225'
													)
												"
												@confirm="() => del(record.Id)"
											>
												<a-button
													size="small"
													style="
														margin-left: 9px;
														width: 100%;
														text-align: left;
													"
													type="link"
													>{{
														$t(
															'menu.exception.trigger'
														)
													}}</a-button
												>
											</a-popconfirm>
										</a-menu-item>
										<a-menu-item
											@click="showPermissions(record)"
											v-if="
												record.RpaCreatePeople ===
													userdata.YtId ||
												record.RpaLeaderMasterId ===
													userdata.YtId ||
												record.RpaleaderRetinueId ===
													userdata.YtId
											"
										>
											<!-- 功能权限 -->
											<a-button type="link">{{
												$t(
													'user.verification-code.required1115661105722'
												)
											}}</a-button>
											<Permissions
												ref="myPermissions"
											></Permissions>
										</a-menu-item>
									</a-menu>
								</template>
							</a-dropdown>
						</span>
					</template>
				</a-table-column>
				<!-- 相关DI -->
				<span slot="dataAssetsIdAction" slot-scope="text, record">
					<span v-if="text != ''">{{ text }}</span>
					<span v-else> N/A </span>
				</span>
				<!-- 收集渠道 -->
				<span slot="channelAction" slot-scope="text, record">
					<span v-if="text != ''">{{ text }}</span>
					<span v-else> N/A </span>
				</span>
				<!-- 数据收集或传输的频率 -->
				<span slot="rpaFrequencyAction" slot-scope="text, record">
					<span v-if="text != ''">{{ text }}</span>
					<span v-else> N/A </span>
				</span>
				<!-- 数据控制者 -->
				<span slot="controllerAction" slot-scope="text, record">
					<span v-if="text != ''">{{ text }}</span>
					<span v-else> N/A </span>
				</span>
				<!-- RPA名称 -->
				<span slot="rpaNameAction" slot-scope="text, record">
					<span v-if="text != ''">{{ text }}</span>
					<span v-else> N/A </span>
				</span>
				<span slot="rpaStateAction" slot-scope="text, record">
					<!-- 状态 -->
					<div v-if="record.RpaState == 'Draft'">
						<a-badge color="blue" /> {{ record.RpaState }}
					</div>
					<div v-else-if="record.RpaState == 'Active'">
						<a-badge status="success" /> {{ record.RpaState }}
					</div>
					<div v-else>
						<a-badge color="red" /> {{ record.RpaState }}
					</div>
				</span>
			</a-table>
			<!-- 分页 -->
			<a-pagination
				v-model="pagination.page"
				:pageSize.sync="pagination.pageSize"
				:total="pagination.total"
				hideOnSinglePage
				size="small"
				@change="getList"
			/>
		</a-card>
		<div class="big-box" v-if="ifLoading">
			<a-spin />
		</div>
	</div>
</template>

<script>
import headerBands from './components/headers.vue'
import { rpaDelcsai, rpaDelete, rpaLists, rpCopy } from '@/api/ytdg'
import { rpaSelect } from '@/api/rpa/form'
import axios from 'axios'
import moment from 'moment'
import tableSelect from '@/components/tableSelect/tableSelect.vue'
import { getUserInfo } from '@/api/index'
import Permissions from './Permissions.vue'
import storage from 'store'
import { ACCESS_TOKEN } from '@/store/mutation-types'
import {  dpiaId  } from '@/api/dpia/form'
import DIdetail from '../rpa/components/DIdetail.vue'
import Dpiadetail from '../rpa/components/dpiaDetail.vue'
import {
  appIdCreatexl,
  appidSxq,
} from "@/api/appid";


export default {
	components: {
		Permissions,
		headerBands,
		tableSelect,
		DIdetail,
		Dpiadetail,
	},

	data() {
		return {
			userroleid: '',
			loading: false,
			hasSelected: true,
			selectedRowKeys: [],
			inputValue2: '',
			inputValue1: '',
			inputValue4: '',
			inputValue5: '',
			inputValue6: '',
			clicked1: false,
			clicked2: false,
			clicked3: false,
			clicked4: false,
			clicked5: false,
			clicked6: false,
			// itLang:null,
			inputValue3: '',
			/**table数据 */
			listData: [],
			// table的loading 状态
			listLoading: false,
			queryForm: {},
			// columns,
			visible: false,
			// 分页参数
			pagination: {
				page: 1, //当前页
				pageSize: 10, //每页条数
				total: 0, //总条数
				showQuickJumper: true,
				hideOnSinglePage: true,
			},
			setValusKey: '',
			filterData: [],
			// 暂时存用户数据
			userdata: {},
			kvMap: [
				'',
				'RpaId',
				'RpaName',
				'',
				'RpaLeaderMaster',
				'RpaProcessingActivityCycle',
				'RpaCollectionChannels',
				'RpaState', // 7
				'',
				'',
				'CreatePeople',
				'RpaCreatetime',
				'DataAssetsId',
				'DataAssetsId',
				'DPIAId',
			],
			okyMap: [
				'',
				'RpaIds',
				'RpaNames',
				'RpaDataController',
				'RpaLeaderMaster',
				'',
				'',
				'',
				'',
				'',
				'CreatePeople',
				'',
				'RpaCreatetime', // 创建时间
				'DataAssetsId',
				'DPIAId',
			],
			ifLoading: false,
			initData: {},
			fetchData:{},
            isLable: 0,
            content:''
		}
	},
	created() {
		this.getList()
		this.init()
		this.getinfo()
	},
	mounted() {
		// console.log(this.$refs.myPermissions) // 访问组件实例
    this.dIDetailInit()
		this.DIfetchData()
		this.pluginsBuild()
		let that = this
		window.addEventListener('setItemEvent', function (e) {
			if (e.key == 'lang') {
				let lang = JSON.parse(e.value)
				if (lang == 'zh-EN') {
					that.itLang = false
				} else if (lang == 'zh-CN') {
					that.itLang = true
				}
			}
		})
	},
	methods: {
		async dIDetailInit() {
      /** 搜索数据 */
      const { data: appidLists } = await appIdCreatexl({ content: '' });
      /** 列表数据 */
      const { data: sonfigurationItemsContent } = await appidSxq({ state: 3 });
      // 存放地
      const { data: fonfigurationItemsContent } = await appidSxq({ state: 4 });
      this.initData = {
        sonfigurationItemsContent,
        fonfigurationItemsContent,
        appidLists
      }
    },
		async DIfetchData() {
			const { data: appidLists } = await appIdCreatexl({ content:'' });
			this.fetchData = {
				appidLists
			}
		},
		// 存储数据
		async getinfo() {
			//获取用户信息
			const { data } = await getUserInfo()
			// 获取用户列表下拉
			// 存储数据到sessionStorage
			// sessionStorage.setItem("userinfo", JSON.stringify(data));
			this.userdata = data
			// console.log(data);
		},
		async init() {
			//获取用户信息
			const { data } = await getUserInfo()
			this.userroleid = data.role
			this.pagination.page = 1
			await this.getList()
			// console.log(localStorage.getItem('lang'),'sdsds')
			if (localStorage.getItem('lang') == '"zh-CN"') {
				this.itLang = true
			} else if (localStorage.getItem('lang') == '"zh-EN"') {
				this.itLang = false
			}
			// console.log('this.itLang', this.itLang)
		},
		// 查询Filter逻辑
		async setValus(typeId) {
			this.listLoading = true
			try {
				// 调用查询列表
				const { data } = await rpaSelect({ condition: typeId })
				for (let j = 0; j < data.length; j++) {
					if (typeId === 7) {
						switch (data[j].value) {
							case 1:
								data[j].text = this.$t(
									'user.verification-code.required111566133'
								)
								break
							case 2:
								data[j].text = this.$t(
									'user.verification-code.required111566144'
								)
								break
							case 3:
								data[j].text = this.$t(
									'user.verification-code.required111566145'
								)
								break
							case 4:
								data[j].text = this.$t(
									'user.verification-code.required111566146'
								)
								break
							case 5:
								data[j].text = `${this.$t(
									'user.verification-code.required11156611057737144228143122233556655'
								)}/${this.$t(
									'user.verification-code.required111566122'
								)}`
								break
							default:
								break
						}
					}
				}
				// 赋值类型，用于筛选、搜索的直接调用
				if (localStorage.getItem('lang') == '"zh-CN"') {
					for (let i = 0; i < data.length; i++) {
						data[i].text = data[i].text
					}
				} else if (typeId === 5 || typeId === 6) {
					for (let i = 0; i < data.length; i++) {
						data[i].text = data[i].textEn
					}
				}
				// 赋值筛选的列表，直接赋值
				this.filterData = data
				this.setValusKey = typeId
				// console.log('==============', this.filterData)
			} catch (error) {
				// 报错信息
				this.$message.error(error)
				console.log(error)
			} finally {
				// 不管成功失败都会执行
				this.listLoading = false
			}
		},
		/**
		 * 清空查询数据，并且执行查询
		 * @returns {Promise<void>}
		 */
		async tableCleanJobs(type) {
			this.pagination.page = 1
			if (type === 'part') {
				this.queryForm[this.kvMap[this.setValusKey]] = undefined
				this.queryForm[this.okyMap[this.setValusKey]] = undefined
			} else {
				this.queryForm = {}
				for (let i = 1; i <= 7; i++) {
					let dom = this.$refs[`tableselect${i}`]
					if (dom) {
						dom.inputValue = ''
						dom.inputCheckValue = []
					}
				}
			}
			this.inputValue = ''
			await this.getList()
		},
		/**
		 * 列表搜索查询
		 * @param e 搜索的值
		 * @returns {Promise<void>}
		 */
		async searchQuery(e) {
			this.queryForm[this.kvMap[this.setValusKey]] = undefined
			this.queryForm = {
				...this.queryForm,
				[this.okyMap[this.setValusKey]]: e,
			}
			await this.getList('filter')
		},

		/**
		 * 列表筛选查询
		 * @param e 筛选的值
		 * @returns {Promise<void>}
		 */
		async searchQueryFilter(e, original) {
			this.queryForm[this.okyMap[this.setValusKey]] = undefined
			this.queryForm = {
				...this.queryForm,
				[this.kvMap[this.setValusKey]]:
					this.setValusKey === 4 ? original.join('#@%$') : e,
			}
			await this.getList('filter')
		},
		async pluginsBuild() {
			// 所有初始化入口
			try {
				// 初始化加载图表统计数据
				await this.$refs.headerBands.open()
			} catch (error) {
				console.log('[rpa.index.pluginsBuild]插件初始化异常:', error)
			}
		},
		//table搜索input
		onChange(e) {
			console.log('[rpa.index.onChange]数据请求:', e)
			this.inputData = e.data
		},
		//table搜索1
		async tableSearch1() {
			this.listLoading = true
			const { page, pageSize } = this.pagination
			try {
				// 调用查询列表
				const { data } = await rpaLists({
					...{ page: 1, pageSize: 10 },
					...(this.queryForm = {
						RpaIds: this.inputValue1,
						RpaNames: this.inputValue1,
					}),
				})
				// 解构赋值
				const { Page, PageSize, Total, Lists } = data
				console.log('[rpa.index.tableSearch1]数据请求返回:', Lists)
				// 给table赋值
				this.listData = Lists || []
				// 给分页数据赋值
				this.pagination = {
					page: Page,
					pageSize: PageSize,
					total: Total,
				}
			} catch (error) {
				console.log(this.$t('rpa.index.132027-3'), error)
				console.log('[rpa.index.tableSearch1]数据请求异常:', error)
			} finally {
				this.listLoading = false
			}
			this.clicked1 = false
			this.inputValue1 = ''
		},
		//table1搜索重置
		async ReaTable1() {
			this.pagination.page = 1
			this.queryForm = {}
			this.getList()
			this.inputValue1 = ''
			this.clicked1 = false
		},
		async del(id) {
			try {
				// 传过来的id直接请求删除api
				await rpaDelete({ Id: id })
				this.$message.success(
					this.$t('user.verification-code.required111566110577133')
				)
				// 重新初始化列表刷新数据
				await this.init()
			} catch (error) {
				console.log('[rpa.index.del]数据请求异常:', error)
				this.$message.error(error)
			}
		},
		//功能权限
		async showPermissions(data) {
			//展开可读权限
			await this.$refs.myPermissions.open(data)
		},
		//table搜索7
		async tableSearch2() {
			this.listLoading = true
			const { page, pageSize } = this.pagination
			try {
				// 调用查询列表
				const { data } = await rpaLists({
					...{ page: 1, pageSize: 10 },
					...(this.queryForm = {
						RpaName: this.inputValue2,
					}),
				})
				// 解构赋值
				const { Page, PageSize, Total, Lists } = data
				console.log('[rpa.index.tableSearch2]数据请求返回:', Lists)
				// 给table赋值
				this.listData = Lists || []
				// 给分页数据赋值
				this.pagination = {
					page: Page,
					pageSize: PageSize,
					total: Total,
				}
			} catch (error) {
				console.log('[rpa.index.tableSearch2]数据请求异常:', error)
				// 报错信息
				this.$message.error(error)
			} finally {
				// 不管成功失败都会执行
				this.listLoading = false
			}
			this.clicked2 = false
			this.inputValue2 = ''
		},
		//table1搜索重置
		async ReaTable2() {
			this.pagination.page = 1
			this.queryForm = {}
			this.getList()
			this.inputValue2 = ''
			this.clicked2 = false
		},
		//table搜索7
		async tableSearch3() {
			this.listLoading = true
			const { page, pageSize } = this.pagination
			try {
				// 调用查询列表
				const { data } = await rpaLists({
					...{ page: 1, pageSize: 10 },
					...(this.queryForm = {
						RpaDataController: this.inputValue3,
					}),
				})
				// 解构赋值
				const { Page, PageSize, Total, Lists } = data
				// 给table赋值
				this.listData = Lists || []
				// 给分页数据赋值
				this.pagination = {
					page: Page,
					pageSize: PageSize,
					total: Total,
				}
			} catch (error) {
				// 报错信息
				this.$message.error(error)
			} finally {
				// 不管成功失败都会执行
				this.listLoading = false
			}
			this.clicked3 = false
			this.inputValue3 = ''
		},
		//table1搜索重置
		async ReaTable3() {
			this.pagination.page = 1
			this.queryForm = {}
			this.getList()
			this.inputValue3 = ''
			this.clicked3 = false
		},
		//创建人table搜索10
		async tableSearch4() {
			this.listLoading = true
			const { page, pageSize } = this.pagination
			try {
				// 调用查询列表
				const { data } = await rpaLists({
					...{ page: 1, pageSize: 10 },
					...(this.queryForm = {
						CreatePeople: this.inputValue4,
					}),
				})
				// 解构赋值
				const { Page, PageSize, Total, Lists } = data
				// 给table赋值
				this.listData = Lists || []
				// 给分页数据赋值
				this.pagination = {
					page: Page,
					pageSize: PageSize,
					total: Total,
				}
			} catch (error) {
				// 报错信息
				this.$message.error(error)
			} finally {
				// 不管成功失败都会执行
				this.listLoading = false
			}
			this.clicked4 = false
			this.inputValue4 = ''
		},
		//创建人table搜索 重置
		async ReaTable4() {
			this.pagination.page = 1
			this.queryForm = {}
			this.getList()
			this.inputValue4 = ''
			this.clicked4 = false
		},
		// 关联的数据资产ID 搜索
		async tableSearch5() {
			this.listLoading = true
			const { page, pageSize } = this.pagination
			try {
				// 调用查询列表
				const { data } = await rpaLists({
					...{ page: 1, pageSize: 10 },
					...(this.queryForm = {
						DataAssetsId: this.inputValue5,
					}),
				})
				// 解构赋值
				const { Page, PageSize, Total, Lists } = data
				// 给table赋值
				this.listData = Lists || []
				// 给分页数据赋值
				this.pagination = {
					page: Page,
					pageSize: PageSize,
					total: Total,
				}
			} catch (error) {
				// 报错信息
				this.$message.error(error)
			} finally {
				// 不管成功失败都会执行
				this.listLoading = false
			}
			this.clicked5 = false
			this.inputValue5 = ''
		},
		//关联的数据资产ID 重置
		async ReaTable5() {
			this.pagination.page = 1
			this.queryForm = {}
			this.getList()
			this.inputValue5 = ''
			this.clicked5 = false
		},
		// 关联的DPIA ID  搜索
		async tableSearch6() {
			this.listLoading = true
			const { page, pageSize } = this.pagination
			try {
				// 调用查询列表
				const { data } = await rpaLists({
					...{ page: 1, pageSize: 10 },
					...(this.queryForm = {
						DPIAId: this.inputValue6,
					}),
				})
				// 解构赋值
				const { Page, PageSize, Total, Lists } = data
				// 给table赋值
				this.listData = Lists || []
				// 给分页数据赋值
				this.pagination = {
					page: Page,
					pageSize: PageSize,
					total: Total,
				}
			} catch (error) {
				// 报错信息
				this.$message.error(error)
			} finally {
				// 不管成功失败都会执行
				this.listLoading = false
			}
			this.clicked6 = false
			this.inputValue6 = ''
		},
		// 关联的DPIA ID 重置
		async ReaTable6() {
			this.pagination.page = 1
			this.queryForm = {}
			this.getList()
			this.inputValue6 = ''
			this.clicked6 = false
		},

		//列表删除
		async delcai(id) {
			await rpaDelcsai({ Id: id })
			await this.init()
			this.$message.success(
				this.$t('user.verification-code.required111566110577133')
			)
		},
		// 分页事件 直接复制使用 通用的
		tableChange(e, searchInputs) {
			var parames = Object.keys(searchInputs)
			for (var i = 0; i < parames.length; i++) {
				searchInputs[parames[i]] = searchInputs[parames[i]].join()
			}
			console.log('searchInputs', searchInputs)
			this.queryForm = { ...searchInputs }
			this.getList('filter')
		},
		// 创建成功刷新列表 or 初始化事件 通用的 如果搜索条件有下拉列表 就需要放这里面
		async getList(state) {
			console.log(state)
			this.listLoading = true
			const { page, pageSize } = this.pagination
			try {
				if (state === 'filter') {
					// 调用查询列表
					const { data } = await rpaLists({
						...{ page: 1, pageSize: 10 , isAll:this.isLable },
						...this.queryForm,
					})
					console.log('dataid', data)
					// 解构赋值
					const { Page, PageSize, Total, Lists } = data
					// 给table赋值
					console.log('Lists', Lists)
					this.listData = Lists || []
					// 给分页数据赋值
					this.pagination = {
						page: Page,
						pageSize: PageSize,
						total: Total,
					}
				} else {
					// 调用查询列表
					const { data } = await rpaLists({
						...{ page, pageSize , isAll:this.isLable},
						...this.queryForm,
					})
					console.log('dataid', data)
					// 解构赋值
					const { Page, PageSize, Total, Lists } = data
					// 给table赋值
					console.log('Lists', Lists)
					this.listData = Lists || []
					// 给分页数据赋值
					this.pagination = {
						page: Page,
						pageSize: PageSize,
						total: Total,
					}
				}
				await this.$refs.headerBands.open()
			} catch (error) {
				// 报错信息
				this.$message.error(error)
			} finally {
				// 不管成功失败都会执行
				this.listLoading = false
			}
		},
		showModal(state, itLang) {
			this.$router.push({
				path: '/rpa/detail',
				query: { state, itLang: this.itLang },
			})
		},
		// 修改
		edit(Id, state, itLang) {
			this.$router.push({
				path: '/rpa/detail',
				query: { state: 'edit', id: Id, itLang: this.itLang },
			})
		},
		//查看
		see(Id, state, itLang) {
			this.$router.push({
				path: '/rpa/detail',
				query: { state: 'see', id: Id, itLang: this.itLang },
			})
		},
		// 查询Filter逻辑
		// async setValus(typeId) {
		//   this.listLoading = true
		//   try {
		//     // 调用查询列表
		//     const { data } = await rpaSelect({ condition: typeId })
		//     this.columns[typeId - 1].filters = data;
		//     console.log(data)
		//     console.log('listData', this.listData);
		//   } catch (error) {
		//     // 报错信息
		//     this.$message.error(error)
		//     console.log(error);
		//   } finally {
		//     // 不管成功失败都会执行
		//     this.listLoading = false
		//   }
		// },
		// 复制
		async Copy(Id) {
			const { data } = await rpCopy({ Id: Id })
			this.$message.success(
				this.$t('user.verification-code.required111566110577201')
			)
			console.log('data---------', data)
			this.init()
		},
		onSelectChange(selectedRowKeys) {
			console.log('selectedRowKeys changed: ', selectedRowKeys)
			this.selectedRowKeys = selectedRowKeys
		},
		handleClickChange1(visible) {
			console.log('visible', visible)
			this.clicked1 = visible
		},
		handleClickChange2(visible) {
			console.log('visible', visible)
			this.clicked2 = visible
		},
		handleClickChange3(visible) {
			console.log('visible', visible)
			this.clicked3 = visible
		},
		handleClickChange4(visible) {
			console.log('visible', visible)
			this.clicked4 = visible
		},
		handleClickChange5(visible) {
			console.log('visible', visible)
			this.clicked5 = visible
		},
		handleClickChange6(visible) {
			console.log('visible', visible)
			this.clicked6 = visible
		},
		// // 赋值
		// confirm(e) {
		//   console.log(e);
		//   this.$message.success('删除成功');
		// },

		//导出表格
		async start() {
			let id = this.selectedRowKeys.join(',')
			console.log('id', id)
			// console.log('form',form);
			console.log('this.$store.state', this.$store.state.user.token)
			// let token1 = this.$store.state.user.token;
			try {
				this.ifLoading = true
				const data = await axios({
					url: `${process.env.VUE_APP_BASE_API}/v1/rpa/export`,
					method: 'post',
					params: { id: id },
					headers: {
						// 'Token': token1,
						token: storage.get(ACCESS_TOKEN),
						tokens: storage.get('bmwToken') || '',
					},
					responseType: 'arraybuffer',
				})
				this.ifLoading = false
				if (data.status == 200) {
					const url = window.URL.createObjectURL(
						new Blob([data.data], {
							type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
						})
					)
					const link = document.createElement('a')
					link.style.display = 'none'
					link.href = url
					link.setAttribute(
						'download',
						`平台数据${moment().format('L')}.xls`
					)
					document.body.appendChild(link)
					link.click()
					document.body.removeChild(link)
				} else {
					this.$message.error(
						this.$t(
							'user.verification-code.required111566110577327'
						)
					)
				}
			} catch (error) {
				this.$message.error(error)
			}
		},
		filterOption(input, option) {
			return (
				option.componentOptions.children[0].text
					.toLowerCase()
					.indexOf(input.toLowerCase()) >= 0
			)
		},

		async clickButton(isLable) {
      this.isLable = isLable;
			this.pagination.page = 1
			if ( this.isLable == 0) {
				this.queryForm = {}
			}else if (this.isLable == 1) {
				this.queryForm = {RpaState: 2}
			}
      this.getList()
    },
	},
}
</script>

<style lang="less" scoped>
/deep/ .drawer-form {
	margin-bottom: 40px;

	.ant-form-item {
		margin-right: 50px;
	}

	.checkbox {
		background: #eee;
		padding: 10px;
		margin-top: 16px;
		position: relative;
		top: -10px;
		left: -10px;

		.ant-form-item-label {
			display: inline-block;
			line-height: 40px;
			width: 150px;
			margin-right: 10px;
		}
	}
}

.ant-pagination {
	float: right;
}

.import-butoon {
	float: left;
	margin-top: -50px;
	margin-left: 100px;
}

.big-box {
	width: 100vw;
	height: 100vh;
	background-color: rgba(0, 0, 0, 0.7);
	position: fixed;
	top: 0;
	left: 0;
	z-index: 9999999;
	display: flex;
	justify-content: center;
	align-items: center;
}
.button-text {
  font-size: 13px;
  color: #000000a6;
  transition: color 0.3s;
  border-radius: 0;
  margin-right: 18px;
  border: 0;
  width: 180px;

  &.active {
    border-bottom: 2px solid #5077a5;
  }

  &:hover {
    color: #5077a5;
    border-bottom: 2px solid #5077a5;
  }
}
</style>
